<%	
	/*@ 扩展对象的静态方法 */
	Object.extend
	(
		Date,
		{
			//->解析日期对象或字符串，并返回日期对象
			analyse:function($dateValue)
			{		
				//->String
				//YYYY-MM-DD(,|space)HH:MM:SS
				//YYYY/MM/DD(,|space)HH:MM:SS					
				//MM-DD-YY(,|space)HH:MM:SS
				//MM/DD/YY(,|space)HH:MM:SS
				//July 10 1995 10:00 PM
				//Mon Jul 10 5:00:00 PM UTC+0800 1995
				var argType=Object.varType($dateValue);
				
				if(argType!='string'&&argType!='date') return NaN;	
				
				switch(varType($dateValue))
				{
					case 'string':
						$dateValue=$dateValue.strip();
						if(isNaN(Date.parse($dateValue))==true)
						{	
							if(cusDatetimeRegexp.test($dateValue)==true)
							{
								var _ta=($dateValue.indexOf(',')!=-1) ? ($dateValue.split(',')):($dateValue.split(' '));
								var _taDate=_ta[0].split('-');
								var _taTime;
									try{
										_taTime=_ta[1].split(':');		
									}catch(e){
										_taTime=[];
									}
								if(_taTime=='') _taTime=[0];
								var _ts=_taDate[1]+'/'+_taDate[2]+'/'+_taDate[0];
								(_taTime[0]!=null) ? (_ts+=','+_taTime[0]) : (_ts+=',0');
								(_taTime[1]!=null) ? (_ts+=':'+_taTime[1]) : (_ts+=':0');
								(_taTime[2]!=null) ? (_ts+=':'+_taTime[2]) : (_ts+=':0');
								return new Date(_ts);
							}
							else
							{
								return NaN;
							}
						}
						else
							return new Date($dateValue);
						break;
					case 'date':
						return new Date($dateValue);
						break;
					default:
						return NaN;
				}
			},			
			//->比较两日期之间的差值
			diff:function($datepart,$startDate,$endDate)
			{
				//alert($datepart,$startDate,$endDate)
				var startObjType=Object.varType($startDate),endObjType=Object.varType($endDate);
				
				if(Object.varType($datepart)!='string') return NaN;				
				if((startObjType!='string'&&startObjType!='date')||(endObjType!='string'&&endObjType!='date')) return NaN;				
				if(startObjType=='string'){
					if(cusDatetimeRegexp.test($startDate)==false)
					{
						return NaN;	
					}
				}
				if(endObjType=='string'){
					if(cusDatetimeRegexp.test($endDate)==false)
					{
						return NaN;	
					}
				}				
				
				$datepart=$datepart.toLowerCase();				
				$startDate=(startObjType=='string') ? Date.analyse($startDate):$startDate;
				$endDate=(endObjType=='string') ? Date.analyse($endDate):$endDate;
				if($datepart!=undefined&&(isNaN($startDate)==false&&isNaN($endDate)==false))
				{
					var dateSign=1,tempDate;				
					var timeRes=Date.parse($endDate)-Date.parse($startDate);				
					if(timeRes.isNegative()==true)
					{
						tempDate=$startDate;
						$startDate=$endDate;
						$endDate=tempDate;
						dateSign=-1;
						timeRes=Date.parse($endDate)-Date.parse($startDate);
					}
					if($datepart=='m'||$datepart=='month'||$datepart=='y'||$datepart=='year')
					{
						var timeResYear=0;
						var leapYear=0;
						(($endDate.getFullYear()-$startDate.getFullYear())+1).times
						(
							function($n)
							{
								if((new Date('1/'+'1/'+($startDate.getFullYear()+$n))).isLeap())
								{
									leapYear++;	
								}							
							}
						)
						timeResYear=(((timeRes-leapYear.floor()*366*24*60*60*1000)/1000/60/60/24/365)+leapYear.floor()).toInteger();				
					}
					if($datepart=='y'||$datepart=='year')
					{
						return (dateSign==-1) ? timeResYear*-1 : timeResYear;
					}
					else if($datepart=='m'||$datepart=='month')
					{
						var timeResMonth=timeResYear*12;
						return  (dateSign==-1) ? (timeResMonth*-1):(timeResMonth);
					}
					else if($datepart=='d'||$datepart=='date'||$datepart=='day')
					{
						var timeResDay=timeRes/1000/60/60/24;
						return (dateSign==-1) ? (timeResDay*-1):(timeResDay);
					}
					else if($datepart=='h'||$datepart=='hour')
					{
						var timeResHour=timeRes/1000/60/60;
						return (dateSign==-1) ? (timeResHour*-1):(timeResHour);
					}
					else if($datepart=='mm'||$datepart=='minute')
					{
						var timeResMinute=timeRes/1000/60;
						return (dateSign==-1) ? (timeResMinute*-1):(timeResMinute);
					}
					else if($datepart=='s'||$datepart=='second')
					{
						var timeResSecond=timeRes/1000;
						return (dateSign==-1) ? (timeResSecond*-1):(timeResSecond);
					}
					else if($datepart=='ms'||$datepart=='millisecond')
						return (dateSign==-1) ? (timeRes*-1):(timeRes);
					else
						return NaN;		
				}
				else
				{
					return NaN;
				}
			},	
			//->取现在时间
			now:function($isObject)
			{
				return $isObject!=true ? Now():new Date();	
			},			
			//->返回日期对象某部分的值
			part:function($dateobj,$datepart,$isUTC)
			{	
				var tValue;
				$datepart=$datepart.toLowerCase();
				$isUTC=(varType($isUTC)=='string') ? ($isUTC.toUpperCase()):($isUTC);
				if($datepart=='y'||$datepart=='year')
					tValue=($isUTC==true||$isUTC=='UTC') ? ($dateobj.getUTCFullYear()) : ($dateobj.getFullYear());
				else if($datepart=='m'||$datepart=='month')
					tValue=($isUTC==true||$isUTC=='UTC') ? (($dateobj.getUTCMonth()+1)) : (($dateobj.getMonth()+1));
				else if($datepart=='d'||$datepart=='date')
					tValue=($isUTC==true||$isUTC=='UTC') ? ($dateobj.getUTCDate()) : ($dateobj.getDate());	
				else if($datepart=='dd'||$datepart=='day')
					tValue=($isUTC==true||$isUTC=='UTC') ? ($dateobj.getUTCDay()) : ($dateobj.getDay());	
				else if($datepart=='h'||$datepart=='hour')
					tValue=($isUTC==true||$isUTC=='UTC') ? ($dateobj.getUTCHours()) : ($dateobj.getHours());
				else if($datepart=='mm'||$datepart=='minute')
					tValue=($isUTC==true||$isUTC=='UTC') ? ($dateobj.getUTCMinutes()) : ($dateobj.getMinutes());
				else if($datepart=='s'||$datepart=='second')
					tValue=($isUTC==true||$isUTC=='UTC') ? ($dateobj.getUTCSeconds()) : ($dateobj.getSeconds());
				else if($datepart=='ms'||$datepart=='millisecond')
					tValue=($isUTC==true||$isUTC=='UTC') ? ($dateobj.getUTCMilliseconds()) : ($dateobj.getMilliseconds());				
				else
					tValue=NaN;						
				return tValue;
				
			}		
		}
	);
	/*@ 扩展对象的原型方法 */
	Object.extend
	(
		Date.prototype,
		{
			//->在指定时间值上进行偏移
			add:function($datepart,$value)
			{
				var isArgs=Object.varType($datepart)=='string'&&IsNumeric($value,'integer')==true;	
				if(isArgs==false) return NaN;														
				switch($datepart)				
				{
					case 'year':						
						this.setFullYear(this.getFullYear()+$value);
						return this.getFullYear();
						break;
					case 'month':
						this.setMonth(this.getMonth()+$value);
						return this.getMonth();
						break;
					case 'date':					
						this.setDate(this.getDate()+$value);
						return this.getDate();
						break;					
					case 'hour':
						this.setHours(this.getHours()+$value);	
						return this.getHours();
						break;
					case 'minute':
						this.setMinutes(this.getMinutes()+$value);						
						return this.getMinutes();
						break;	
					case 'second':
						this.setSeconds(this.getSeconds()+$value);
						return this.getSeconds();
						break;	
					case 'millisecond':
						this.setMilliseconds(this.getMilliseconds()+$value);
						return this.getMilliseconds();
						break;							
					default:
						return NaN;		
				}								
			},	
			//->比较时间对象与指定时间对象这间的差
			diff:function($datepart,$endDate)
			{
				return Date.diff($datepart,this,$endDate);
			},	
			//->判定闰年
			isLeap:function($isUTC)
			{
				var _tYear=($isUTC==true||$isUTC=='UTC') ? (this.getUTCFullYear()):(this.getFullYear());
				return (_tYear%400==0)||((_tYear%100!=0)&&(_tYear%4==0));	
			},
			//->返回格式化的字符串
			toCommString:function($isHaveTime,$connector,$toTimeConnector,$format)
			{
				//->String
				//options {foramt,isHaveTime:}
				//YYYY-MM-DD(,|space)HH:MM:SS
				//YYYY/MM/DD(,|space)HH:MM:SS					
				//MM-DD-YY(,|space)HH:MM:SS
				//MM/DD/YY(,|space)HH:MM:SS
				//July 10 1995 10:00 PM
				//Mon Jul 10 5:00:00 PM UTC+0800 1995

				$format=($format||'YMD'),$connector=($connector||'-');
				$toTimeConnector=($toTimeConnector||' ');
				
				if($isHaveTime==undefined) $isHaveTime=true;
				
				var objVarType=Object.varType(this);				
				
				if(objVarType=='string'||objVarType=='date')
				{
					var tObj=(objVarType=='string') ? Date.analyse(this):this;	
					var tText='';
					if(isNaN(tObj)==true)
					{
						return undefined;
					}
					else
					{
						var tDateText_YMD='',tDateText_MDY='',tTimeText='';
						var tArray=
						[
							[tObj.year(),tObj.month(),tObj.date()],
							[tObj.month(),tObj.date(),tObj.year()],
							[tObj.hour(),tObj.minute(),tObj.second()]
						];
						
						tArray.each
						(
							function($v,$i)
							{
								if($i!=2)
								{
									if($i==0)
									{
										$v.map
										(
											function($v,$i){
												tDateText_YMD+=($v.toPaddedString(2)+($i!=2 ? '-':''));
											}
										);									
									}
									else
									{
										$v.map
										(
											function($v,$i){
												tDateText_MDY+=($v.toPaddedString(2)+($i!=2 ? '-':''));
											}
										);									
									}
								}
								else
								{
									$v.map
									(
										function($v,$i){
											tTimeText+=($v.toPaddedString(2)+($i!=2 ? ':':''));
										}
									);								
								}
							}
						);					
						switch($format.toUpperCase())
						{
							case 'YMD':
								tText=tDateText_YMD;
								break;
							case 'MDY':
								tText=tDateText_MDY;
								break;
							default:
								tText=tDateText_YMD;
						}						
						if($connector!='-') tText=tText.replace(/\-/g,$connector);
						if($isHaveTime==true) tText+=$toTimeConnector+tTimeText;						
					}
					tObj=null;
					return tText;
				}
				else{
					return undefined;						
				}
			},			
			//->返回日期对象某部分的值	
			year:function($isUTC)
			{
				return Date.part(this,'year',$isUTC);	
			},
			month:function($isUTC)
			{
				return Date.part(this,'month',$isUTC);	
			},
			date:function($isUTC)
			{
				return Date.part(this,'date',$isUTC);	
			},
			day:function($isUTC)
			{
				return Date.part(this,'day',$isUTC);	
			},		
			hour:function($isUTC)
			{
				return Date.part(this,'hour',$isUTC);	
			},
			minute:function($isUTC)
			{
				return Date.part(this,'minute',$isUTC);	
			},		
			second:function($isUTC)
			{
				return Date.part(this,'second',$isUTC);	
			},	
			milliSecond:function($isUTC)
			{
				return Date.part(this,'millisecond',$isUTC);	
			}		
		}
	);	
	/*@ 扩展对象方法别名 */
	Object.extend
	(
		Date,
		{
			name:Date.part
		}
	);
%>